package cn.firmboy.noun;

import org.junit.Test;

/**
 * java类加载的测试
 *
 * @author firmboy
 * @create 2018-04-24 上午7:29
 **/
public class Load {

    @Test
    public void testStatic(){
        //测试一下类在加载时的顺序
        new Load();

    }

    public static void main(String[] args){
        //new ExtendSuper();
        new Sub();
        System.out.println("-------------------");
        new ExtendSuper();
    }

}

class Super{

    static int getA(){
        System.out.println("初始化super的静态变量");
        return 1;
    }

    int getB(){
        System.out.println("初始化super的实例变量");
        return 2;
    }

    static int a = getA();

    int b = getB();

    static {
        System.out.println("初始化super的静态代码块");
    }


    {
        System.out.println("初始化super的普通代码块");
    }

    Super(){
        System.out.println("super的构造方法被调用");
    }

}


class ExtendSuper extends Super{
    static int getA(){
        System.out.println("初始化extendSuper的静态变量");
        return 1;
    }

    @Override
    int getB(){
        System.out.println("初始化extendSuper的实例变量");
        return 2;
    }

    static int a = getA();

    int b = getB();

    static {
        System.out.println("初始化extendSuper的静态代码块");
    }


    {
        System.out.println("初始化extendSuper的普通代码块");
    }

    ExtendSuper(){
        System.out.println("extendSuper的构造方法被调用");
    }
}


class Sub extends Super{
    static int getC(){
        System.out.println("初始化sub的静态变量");
        return 1;
    }

    int getD(){
        System.out.println("初始化sub的实例变量");
        return 2;
    }

    static int a = getC();

    int b = getD();

    static {
        System.out.println("初始化sub的静态代码块");
    }


    {
        System.out.println("初始化sub的普通代码块");
    }

    Sub(){
        System.out.println("sub的构造方法被调用");
    }
}




class SuperTest{

    void getA(){

    }

}


class SubTest extends SuperTest{

    @Override
    public void getA(){

    }
}